#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>

#include <time.h>
#include <ctype.h>
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
#include "os_api.h"
#include "debug.h"
#include "pwm.h"

#define PWM_STACK_SIZE		(1024*3)

static void* pwm_task_stack = NULL;

static OSTaskRef pwm_task_ref = NULL;


static void pwm_task(void *ptr)
{
	
	OSATaskSleep(10*200);
	
	LOG_PRINTF("pwm_task");
	
	int i;
	int gpio_num3 = 70;//PWM2
	//50us/100us
	int high_one_cycle_duration3 = 50; 
	int total_one_cycle_duration3 = 100;
	hal_PwmConfig(gpio_num3, PWM_CYCLE_ABOVE_1US, high_one_cycle_duration3, total_one_cycle_duration3);	//产生10k-200khz pwm
	hal_PwmEnable(gpio_num3);
	
	while(1) 
	{
		LOG_PRINTF("pwm test is running!!!\n");
		OSATaskSleep(5*200);
		
		for(i=0;i<=100;i++)
		{
			high_one_cycle_duration3=i;	
			hal_PwmConfig(gpio_num3, PWM_CYCLE_ABOVE_1US,high_one_cycle_duration3,total_one_cycle_duration3);
			LOG_PRINTF("high_one_cycle_duration3=%d\n",high_one_cycle_duration3);
			
			OSATaskSleep(100);
		}
	}
		
}


int main(void)
{
    int ret;
	
	pwm_task_stack = malloc(PWM_STACK_SIZE);
	ASSERT(pwm_task_stack != NULL);

    ret = OSATaskCreate(&pwm_task_ref, pwm_task_stack, PWM_STACK_SIZE, 100, "pwm_task", pwm_task, NULL);
    ASSERT(ret == OS_SUCCESS);

	return 0; 
}
